package com.hundsun.fcp.activity;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.View.OnClickListener;

import com.hundsun.fcp.R;
import com.hundsun.fcp.adapter.BankManagerAdapter;
import com.hundsun.fcp.base.BaseActivity;
import com.hundsun.fcp.common.FcpConfig;
import com.hundsun.fcp.common.Redirect;
import com.hundsun.fcp.common.utils.DensityUtil;
import com.hundsun.fcp.dialog.TransPwdDialog;
import com.hundsun.fcp.dialog.UIActionSheetDialog;
import com.hundsun.fcp.dialog.UIActionSheetDialog.OnSheetItemClickListener;
import com.hundsun.fcp.widget.swipelistview.SwipeMenu;
import com.hundsun.fcp.widget.swipelistview.SwipeMenuCreator;
import com.hundsun.fcp.widget.swipelistview.SwipeMenuItem;
import com.hundsun.fcp.widget.swipelistview.SwipeMenuListView;
import com.hundsun.fcp.widget.swipelistview.SwipeMenuListView.OnMenuItemClickListener;

public class BankManagerActivity extends BaseActivity {
	
	private SwipeMenuListView mListView ;
	private SwipeMenuCreator creator;
	
	private BankManagerAdapter mAdapter ;

	@Override
	protected int getContentLayout() {
		return R.layout.activity_manager_banks;
	}
	
	@Override
	protected void initHeader() {
		super.initHeader();
		mHeaderMenu.setRightBG(R.drawable.add_bank) ;
		mHeaderMenu.setTitle(R.string.mine_bankcard) ;
		mHeaderMenu.setRightClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Redirect.startBankAdd(BankManagerActivity.this) ;
			}
		}) ;
	}
	
	@Override
	public void initView() {
		super.initView();
		mAdapter = new BankManagerAdapter(this) ;
		mListView = (SwipeMenuListView) findViewById(R.id.listView) ;
		mListView.setAdapter(mAdapter) ;
		initSwipeMenuCreator() ;
		initSwipeListView() ;
	}
	
	private void initSwipeListView() {
		mListView.setMenuCreator(creator);
		mListView.setOnMenuItemClickListener(new OnMenuItemClickListener() {
			@Override
			public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
				//BankBean item = mAdapter.getItem(position);
				switch (index) {
				case 0:
					// detele 
					final UIActionSheetDialog dialog = new UIActionSheetDialog(
							BankManagerActivity.this);
					//dialog.setTitle("确定要退出登录吗？");
					dialog.addSheetItem("删除", Color.RED,
							new OnSheetItemClickListener() {
								@Override
								public void onClick() {
									try {
										TransPwdDialog dialog = new TransPwdDialog(BankManagerActivity.this) ;
										dialog.show() ;
									} catch (Exception e) {
										if (FcpConfig.debugon)
											e.printStackTrace();
									}
								}
							});

					dialog.show();
				}
				return false;
			}
		});
	}

	private void initSwipeMenuCreator() {
		creator = new SwipeMenuCreator() {

			@Override
			public void create(SwipeMenu menu) {
				// create "open" item
				SwipeMenuItem deleteItem = new SwipeMenuItem(
						getApplicationContext());
				// set item background
				deleteItem.setBackground(new ColorDrawable(getResources().getColor(R.color.red_main_color)));
				// set item width
				deleteItem.setWidth(DensityUtil.dip2px(BankManagerActivity.this, 70));
				// set item title
				deleteItem.setTitle("删除");
				// set item title fontsize
				deleteItem.setTitleSize(18);
				// set item title font color
				deleteItem.setTitleColor(Color.WHITE);
				// add to menu
				menu.addMenuItem(deleteItem);
				 
			}
		};
	}

}
